package com.cskaoyan.app.service.impl;

import com.cskaoyan.app.bean.common.BasePageInfo;
import com.cskaoyan.app.bean.po.MarketComment;
import com.cskaoyan.app.bean.po.MarketCommentExample;
import com.cskaoyan.app.mapper.MarketCommentMapper;
import com.cskaoyan.app.service.AdminCommmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminCommmentServiceImpl implements AdminCommmentService {
    @Autowired
    MarketCommentMapper marketCommentMapper;

    @Override
    public void deleteComment(MarketComment marketComment) {
        Integer id = marketComment.getId();
        MarketCommentExample example = new MarketCommentExample();
        MarketCommentExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(id);
        MarketComment comment = new MarketComment();
        comment.setDeleted(true);
        marketCommentMapper.updateByExampleSelective(comment,example);
    }

    @Override
    public List<MarketComment> getCommentList(BasePageInfo basePageInfo, Integer userId, Integer valueId) {
        MarketCommentExample example = new MarketCommentExample();
        MarketCommentExample.Criteria criteria = example.createCriteria();
        example.setOrderByClause(basePageInfo.getSort()+" "+basePageInfo.getOrder());
        if(userId!=null){

            criteria.andUserIdEqualTo(userId);

        }
        if (valueId != null) {

            criteria.andValueIdEqualTo(valueId);
        }
        criteria.andDeletedEqualTo(false);
        criteria.andAdminContentEqualTo("");
        List<MarketComment> list = marketCommentMapper.selectByExample(example);
        return list;
    }
}
